home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1999 #2 / Amiga Plus CD - 1999 - No. 2.iso / System-Boost / Grafik / BMP2SPEC / Source / BMP2SPEC.amiga.c next >
C/C++ Source or Header  |  1998-06-21  |  5KB  |  424 lines

  1. /* BMP2SPEC version 1.0 */
  2.  
  3. /* By the infamous BLOOD! */
  4.  
  5. /* (C)1996 Cheese Freak Software */
  6.  
  7. /* This prog is most definitely FREEWARE! */
  8.  
  9. /* But please don't distribute updated versions without asking first...! */
  10.  
  11. /* Amiga compilation with AmigaOS version string, Chris Young 1998 */
  12.  
  13. #include <stdio.h>
  14.  
  15. #include <stdlib.h>
  16.  
  17. #include "bmp2spec.h"
  18.  
  19.  
  20.  
  21. void main(int argc, char *argv[])
  22.  
  23. {
  24.  
  25.     FILE *fp1, *fp2;
  26.  
  27.     BYTE header[24],checkbit=255,data[6144], screen[6144];
  28.  
  29.     int count,count2,ptr,ptr2,ptr3,x,y,z,result;
  30.  
  31. char *ver = "$VER:BMP2SPEC 1.0 (13.06.98)";
  32.  
  33.     getheader(header);
  34.  
  35.     printf("\nBMP2SPEC version 1.0\n");
  36.  
  37.     printf("Written by the infamous BLOOD!\naka l.d.tonks@bra0202.wins.icl.co.uk\n");
  38.  
  39.     printf("(C)1996 Cheese Freak Software\n\n");
  40.  
  41.     printf("This program is FREEWARE! Don't pay more than 2p for it!\n\n");
  42.  
  43.  
  44.     if(argc!=3)
  45.  
  46.     {
  47.     printf("**** IMPORTANT! ****\n");
  48.     printf("Set STACK 50000 before trying to run this program, or it'll crash!\n\n");
  49.  
  50.         printf("Usage : BMP2SPEC <bitmap file input> <tape file output>\n");
  51.  
  52.         printf("Example : BMP2SPEC jetset.bmp jetset.tap\n\n");
  53.  
  54.         exit(0);
  55.  
  56.     }
  57.  
  58.     else
  59.  
  60.     {
  61.  
  62.         printf("Converting %s to %s....\n",argv[1],argv[2]);
  63.  
  64.         fp1=fopen(argv[1],"rb");
  65.  
  66.         if(fp1==NULL)
  67.  
  68.         {
  69.  
  70.             printf("Error opening %s...!\n",argv[1]);
  71.  
  72.             exit(1);
  73.  
  74.         };
  75.  
  76.         fp2=fopen(argv[2],"wb");
  77.  
  78.         if(fp2==NULL)
  79.  
  80.         {
  81.  
  82.             printf("Error opening %s...!\n",argv[2]);
  83.  
  84.             exit(1);
  85.  
  86.         };
  87.  
  88.  
  89.  
  90.         result=fwrite(header,24,1,fp2);
  91.  
  92.         if(result!=1)
  93.  
  94.         {
  95.  
  96.             printf("Can't write to %s...!\n",argv[2]);
  97.  
  98.             exit(1);
  99.  
  100.         };
  101.  
  102.         
  103.  
  104.         result=fread(data,62,1,fp1);
  105.  
  106.         if(result!=1)
  107.  
  108.         {
  109.  
  110.             printf("Can't read from %s...!\n",argv[1]);
  111.  
  112.             exit(1);
  113.  
  114.         };
  115.  
  116.  
  117.  
  118.         printf("Reading bitmap data...\n");
  119.  
  120.         result=fread(screen,6144,1,fp1);
  121.  
  122.         if(result!=1)
  123.  
  124.         {
  125.  
  126.             printf("Read error in %s...!\n",argv[1]);
  127.  
  128.             exit(1);
  129.  
  130.         };
  131.  
  132.         
  133.  
  134.         printf("Sorting bitmap data...\n");
  135.  
  136.         ptr=0;
  137.  
  138.         ptr2=6144;
  139.  
  140.         ptr3=0;
  141.  
  142.         for(count=0;count<192;count++)
  143.  
  144.         {
  145.  
  146.             ptr2=ptr2-32;
  147.  
  148.             ptr3=ptr2;
  149.  
  150.             for(count2=0;count2<32;count2++)
  151.  
  152.             {
  153.  
  154.                 data[ptr]=screen[ptr3];
  155.  
  156.                 ptr++;
  157.  
  158.                 ptr3++;
  159.  
  160.             };
  161.  
  162.         };
  163.  
  164.  
  165.  
  166.         printf("Creating Spectrum Screen...\n");        
  167.  
  168.         x=0;
  169.  
  170.         y=0;
  171.  
  172.         z=0;
  173.  
  174.         
  175.  
  176.         for(count=0;count<2048;count++)
  177.  
  178.         {
  179.  
  180.             screen[count]=data[x+(y*32)];
  181.  
  182.             screen[count]=screen[count]^255;
  183.  
  184.             checkbit = (checkbit ^ screen[count]);
  185.  
  186.             x++;
  187.  
  188.             if(x>=32)
  189.  
  190.             {
  191.  
  192.                 x=0;
  193.  
  194.                 y=y+8;
  195.  
  196.                 if(y>=64)
  197.  
  198.                 {
  199.  
  200.                     z++;
  201.  
  202.                     y=z;
  203.  
  204.                 };
  205.  
  206.             };
  207.  
  208.         };
  209.  
  210.  
  211.  
  212.         x=0;
  213.  
  214.         y=64;
  215.  
  216.         z=64;
  217.  
  218.         
  219.  
  220.         for(count=2048;count<4096;count++)
  221.  
  222.         {
  223.  
  224.             screen[count]=data[x+(y*32)];
  225.  
  226.             screen[count]=screen[count]^255;
  227.  
  228.             checkbit = (checkbit ^ screen[count]);
  229.  
  230.             x++;
  231.  
  232.             if(x>=32)
  233.  
  234.             {
  235.  
  236.                 x=0;
  237.  
  238.                 y=y+8;
  239.  
  240.                 if(y>=128)
  241.  
  242.                 {
  243.  
  244.                     z++;
  245.  
  246.                     y=z;
  247.  
  248.                 };
  249.  
  250.             };
  251.  
  252.         };
  253.  
  254.  
  255.  
  256.         x=0;
  257.  
  258.         y=128;
  259.  
  260.         z=128;
  261.  
  262.         
  263.  
  264.         for(count=4096;count<6144;count++)
  265.  
  266.         {
  267.  
  268.             screen[count]=data[x+(y*32)];
  269.  
  270.             screen[count]=screen[count]^255;
  271.  
  272.             checkbit = (checkbit ^ screen[count]);
  273.  
  274.             x++;
  275.  
  276.             if(x>=32)
  277.  
  278.             {
  279.  
  280.                 x=0;
  281.  
  282.                 y=y+8;
  283.  
  284.                 if(y>=192)
  285.  
  286.                 {
  287.  
  288.                     z++;
  289.  
  290.                     y=z;
  291.  
  292.                 };
  293.  
  294.             };
  295.  
  296.         };
  297.  
  298.  
  299.  
  300.         printf("Writing TAP file...\n");
  301.  
  302.         result=fwrite(screen,6144,1,fp2);
  303.  
  304.         if(result!=1)
  305.  
  306.         {
  307.  
  308.             printf("Error writing to %s...!\n",argv[2]);
  309.  
  310.             exit(1);
  311.  
  312.         };
  313.  
  314.  
  315.  
  316.         data[0]=56;
  317.  
  318.         for(count=0;count<768;count++)
  319.  
  320.         {
  321.  
  322.             result=fwrite(data,1,1,fp2);
  323.  
  324.             if(result!=1)
  325.  
  326.             {
  327.  
  328.                 printf("Error writing to %s...!\n",argv[2]);
  329.  
  330.                 exit(1);
  331.  
  332.             };
  333.  
  334.  
  335.  
  336.         };
  337.  
  338.         
  339.  
  340.         result=fwrite(&checkbit,1,1,fp2);
  341.  
  342.         if(result!=1)
  343.  
  344.         {
  345.  
  346.             printf("Error writing to %s...!\n",argv[2]);
  347.  
  348.             exit(1);
  349.  
  350.         };
  351.  
  352.         
  353.  
  354.         printf("\nConversion done...!\n");
  355.  
  356.  
  357.  
  358.         fclose(fp1);
  359.  
  360.         fclose(fp2);
  361.  
  362.     };
  363.  
  364. }
  365.  
  366.  
  367.  
  368.  
  369.  
  370. void getheader(BYTE header[24])
  371.  
  372. {
  373.  
  374.     header[0]=19;    
  375.  
  376.     header[1]=0;    
  377.  
  378.     header[2]=0;    
  379.  
  380.     header[3]=3;    
  381.  
  382.     header[4]=115;    
  383.  
  384.     header[5]=99;    
  385.  
  386.     header[6]=114;    
  387.  
  388.     header[7]=101;    
  389.  
  390.     header[8]=101;    
  391.  
  392.     header[9]=110;    
  393.  
  394.     header[10]=32;    
  395.  
  396.     header[11]=32;    
  397.  
  398.     header[12]=32;    
  399.  
  400.     header[13]=32;    
  401.  
  402.     header[14]=0;    
  403.  
  404.     header[15]=27;    
  405.  
  406.     header[16]=0;    
  407.  
  408.     header[17]=64;    
  409.  
  410.     header[18]=0;    
  411.  
  412.     header[19]=128;    
  413.  
  414.     header[20]=212;    
  415.  
  416.     header[21]=2;    
  417.  
  418.     header[22]=27;    
  419.  
  420.     header[23]=255;    
  421.  
  422. }
  423.  
  424.